/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
* 注意：
* 本软件为www.yixiang.co开发研制，未经购买不得使用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package co.yixiang.modules.system.rest;
import java.util.Arrays;
import co.yixiang.dozer.service.IGenerator;
import co.yixiang.modules.user.domain.ManagementAwardData;
import co.yixiang.modules.user.service.ManagementAwardDataService;
import co.yixiang.modules.user.service.dto.ManagementAwardDataDto;
import co.yixiang.modules.user.service.dto.ManagementAwardDataQueryCriteria;
import lombok.AllArgsConstructor;
import co.yixiang.logging.aop.log.Log;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import co.yixiang.domain.PageResult;
/**
* @author lsh
* @date 2021-05-12
*/
@AllArgsConstructor
@Api(tags = "managementAwardData管理")
@RestController
@RequestMapping("/api")
public class ManagementAwardDataController {

    private final ManagementAwardDataService managementAwardDataService;
    private final IGenerator generator;


    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/managementAwardData/download")
    @PreAuthorize("@el.check('admin','managementAwardData:list')")
    public void download(HttpServletResponse response, ManagementAwardDataQueryCriteria criteria) throws IOException {
        managementAwardDataService.download(generator.convert(managementAwardDataService.queryAll(criteria), ManagementAwardDataDto.class), response);
    }

    @GetMapping(value = "/managementAwardData")
    @Log("查询managementAwardData")
    @ApiOperation("查询managementAwardData")
    @PreAuthorize("@el.check('admin','MANAGEMENTAWARDDATA_ALL','MANAGEMENTAWARDDATA_SELECT')")
    public ResponseEntity<PageResult<ManagementAwardDataDto>> getManagementAwardDatas(ManagementAwardDataQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(managementAwardDataService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping(value = "/managementAwardData")
    @Log("新增managementAwardData")
    @ApiOperation("新增managementAwardData")
    @PreAuthorize("@el.check('admin','MANAGEMENTAWARDDATA_ALL','MANAGEMENTAWARDDATA_CREATE')")
    public ResponseEntity<Object> create(@Validated @RequestBody ManagementAwardData resources){
        return new ResponseEntity<>(managementAwardDataService.save(resources),HttpStatus.CREATED);
    }

    @PutMapping(value = "/managementAwardData")
    @Log("修改managementAwardData")
    @ApiOperation("修改managementAwardData")
    @PreAuthorize("@el.check('admin','MANAGEMENTAWARDDATA_ALL','MANAGEMENTAWARDDATA_EDIT')")
    public ResponseEntity<Object> update(@Validated @RequestBody ManagementAwardData resources){
        managementAwardDataService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除managementAwardData")
    @ApiOperation("删除managementAwardData")
    @PreAuthorize("@el.check('admin','MANAGEMENTAWARDDATA_ALL','MANAGEMENTAWARDDATA_DELETE')")
    @DeleteMapping(value = "/managementAwardData/{id}")
    public ResponseEntity<Object> delete(@PathVariable Integer id) {
            managementAwardDataService.removeById(id);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
